﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace DataLibrary
{
   public class Ctbl_Category:IData<tbl_Category>
    {
       public Ctbl_Category() { }
       public Ctbl_Category(String myconnecString)
           : base(myconnecString)
       { 

       }

       

       public override List<tbl_Category> GetAll(tbl_Category item)
       {
           throw new NotImplementedException();
       }

       public override tbl_Category GetItemById(object id)
       {
           return GetAll().SingleOrDefault(p => p.IdCat == Convert.ToUInt32(id));
       }

       public override tbl_Category GetItem(System.Data.IDataReader dr)
       {
           tbl_Category obj = new tbl_Category();
           obj.IdCat = Convert.ToInt32(dr[tbl_Category.c_idCat]);
           obj.IsActive = Convert.ToInt32(dr[tbl_Category.c_isActive]);
           obj.OrderId = Convert.ToInt32(dr[tbl_Category.c_orderId]);
           obj.ShowTop = Convert.ToBoolean(dr[tbl_Category.c_ShowTop]);
           obj.Description = Convert.ToString(dr[tbl_Category.c_Description]);
           return obj;
       }

       public override List<tbl_Category> GetAll()
       {
           return GetAll("select * from " + tbl_Category.b_tbl_Category + strAsc, CommandType.Text);
       }

       protected override int InsertOnSubmit(tbl_Category item, int t)
       {
           int id = -1;
               id = connec.ExecuteNonQuery("CRUDCategory", CommandType.StoredProcedure, new SqlParameter("@" + tbl_Category.c_Description, item.Description),
                  new SqlParameter("@flag", t), new SqlParameter("@" + tbl_Category.c_idCat, item.IdCat),
                  new SqlParameter("@" + tbl_Category.c_isActive, item.IsActive), new SqlParameter("@" + tbl_Category.c_orderId, item.OrderId),
                  new SqlParameter("@" + tbl_Category.c_ShowTop, item.ShowTop));
           
           return id;
       }


       
    }
}
